package br.com.financeiro.controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Component;

import br.com.financeiro.dominio.Papel;
import br.com.financeiro.services.CrudService;

@Component
@Scope("session")
public class PapelMBean extends CrudMBean<Papel> {
	
	public PapelMBean() {
		obj = new Papel();
	}

	@Override
	protected String getDir() {
		return "/pages";
	}
	
	@Autowired
	protected void setService(CrudService<Papel> service) {
		super.setService(service);
	}
	
	@Override
	@Secured("ROLE_ADMIN")
	public String novo() {
		return super.novo();
	}
	
	// Retorna a lista de papeis
	public List<Papel> listaPapel() {
		List<Papel> listaDePapeis = new ArrayList<Papel>();
		
		getListagem();
		
		for(int i = 0; i < listagem.getRowCount(); ++i) {
			listagem.setRowIndex(i);
			listaDePapeis.add((Papel)listagem.getRowData());
		}
		return listaDePapeis;
	}

}
